package file;

import java.io.*;

//字符流Reader和Writer的使用
public class Demo7 {
    //Writer
    public static void main(String[] args) {
        try(Writer writer = new FileWriter("./output.txt",true)){
            writer.write("王昊天是天才");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //Reader
    public static void main1(String[] args) {
        try(Reader reader = new FileReader("./test.txt")){
            while(true){
//                //一个一个字符读
//                int c = reader.read();
//                if(c == -1){
//                    //读完了文件
//                    break;
//                }
//                System.out.println((char) c);

                //一次读多个字符
                char[] chars = new char[1024];
                int n = reader.read(chars);
                if(n == -1){
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.println(chars[i]);
                }

            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
